<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.prime.com.tr/ui"
        xmlns:ut="http://java.sun.com/jsf/composite/components/tags">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <f:view contentType="text/html">
    <h:head>
        <title>Информация о предмете</title>
    </h:head>
    <h:body>
        <h:form id="thingForm">
            <h:outputLabel value="#{thingBean.message}"/>
            <br/>
            <h:outputLabel value="Добрый день, #{mainPage.userName}"/>
            <br/>
            <p:panel header="Выбранный предмет" >
                <h:outputLabel value="#{thingBean.thing.thingType.name}"/>
                <br/>
                <h:outputLabel value="#{thingBean.thing.additionalOption}"/>
            </p:panel>


            <p:outputPanel id="fork" >
                <p:outputPanel id="forSalePanel" rendered="#{thingBean.owner}" >
                    <h:outputLabel for="startPrice" value="Стартовая цена"/>
                    <p:spinner id="startPrice" value="#{thingBean.startPrice}"/>
                    <h:commandButton value="Выставить на торги" action="#{thingBean.tryToSell}" />
                </p:outputPanel>

                <p:outputPanel id="forBuyPanel" rendered="#{thingBean.thingOnSale}" >
                    <h:outputLabel for="newBidValue" value="Новая ставка"/>
                    <p:spinner id="newBidValue" label="Ставка" value="#{thingBean.newPrice}"/>
                    <p:commandButton id="doNewBid" value="Сделать ставку" action="#{thingBean.doNewBid}" global="false" update="thingForm:bids, thingForm:aboutWinnerPanel" />
                    <p:poll interval="1" update="thingForm:bids, thingForm:aboutWinnerPanel" autoStart="true" listener="#{thingBean.fakeListener}" />

                    <h:outputLabel rendered="#{not empty thingBean.lot}" value="Начальная цена: #{thingBean.lot.startPrice}"/>

                    <p:dataTable id="bids" value="#{thingBean.bidsForLot}" var="bid">

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Время ставки" />
                            </f:facet>
                            <h:outputText value="#{bid.date}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Размер ставки" />
                            </f:facet>
                            <h:outputText value="#{bid.price}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Пользователь" />
                            </f:facet>
                            <h:outputText value="#{bid.user.name}"/>
                        </p:column>

                    </p:dataTable>
                </p:outputPanel>

            </p:outputPanel>

            <br/>
            <p:outputPanel id="aboutWinnerPanel" >
                <p:outputPanel rendered="#{not empty thingBean.lot and not thingBean.lot.open}" >
                    <h:outputLabel value="Победитель: #{thingBean.lot.winnersBid.user.name}, заплативший #{thingBean.lot.winnersBid.price}" />
                </p:outputPanel>
                <p:outputPanel rendered="#{not empty thingBean.lot and thingBean.lot.open and not empty thingBean.bidsForLot}">
                    <h:outputLabel value="Лот будет продан через #{thingBean.backCounter} секунд, если не сделать ставку"/>
                </p:outputPanel>
            </p:outputPanel>
        </h:form>
    </h:body>
    </f:view>
</html>

</ui:composition>

